<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=11"/>
<meta name="generator" content="Doxygen 1.9.2"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>miniFOC: hardware/uart.c Source File</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/searchdata.js"></script>
<script type="text/javascript" src="search/search.js"></script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  <td id="projectlogo"><img alt="Logo" src="Acme_LOGO.png"/></td>
  <td id="projectalign" style="padding-left: 0.5em;">
   <div id="projectname">miniFOC<span id="projectnumber">&#160;1.0.2</span>
   </div>
   <div id="projectbrief">This open-source project aims to accomplish a FOC(Field Oriented Control) scheme that is operatable with minimum costs in China.</div>
  </td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.9.2 -->
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&amp;dn=expat.txt MIT */
var searchBox = new SearchBox("searchBox", "search",'Search','.html');
/* @license-end */
</script>
<script type="text/javascript" src="menudata.js"></script>
<script type="text/javascript" src="menu.js"></script>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&amp;dn=expat.txt MIT */
$(function() {
  initMenu('',true,false,'search.php','Search');
  $(document).ready(function() { init_search(); });
});
/* @license-end */
</script>
<div id="main-nav"></div>
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>

<div id="nav-path" class="navpath">
  <ul>
<li class="navelem"><a class="el" href="dir_42e555215cde261dd5295a864caa3e52.html">hardware</a></li>  </ul>
</div>
</div><!-- top -->
<div class="header">
  <div class="headertitle"><div class="title">uart.c</div></div>
</div><!--header-->
<div class="contents">
<a href="uart_8c.html">Go to the documentation of this file.</a><div class="fragment"><div class="line"><a id="l00001" name="l00001"></a><span class="lineno">    1</span><span class="comment">/**************************************************************************/</span></div>
<div class="line"><a id="l00011" name="l00011"></a><span class="lineno">   11</span><span class="preprocessor">#include &quot;<a class="code" href="uart_8h.html">uart.h</a>&quot;</span></div>
<div class="line"><a id="l00012" name="l00012"></a><span class="lineno">   12</span><span class="preprocessor">#include &quot;<a class="code" href="config_8h.html">config.h</a>&quot;</span></div>
<div class="line"><a id="l00013" name="l00013"></a><span class="lineno">   13</span><span class="preprocessor">#include &quot;gd32f1x0.h&quot;</span></div>
<div class="line"><a id="l00014" name="l00014"></a><span class="lineno">   14</span><span class="preprocessor">#include &quot;<a class="code" href="system_8h.html">system.h</a>&quot;</span></div>
<div class="line"><a id="l00015" name="l00015"></a><span class="lineno">   15</span> </div>
<div class="line"><a id="l00022" name="l00022"></a><span class="lineno"><a class="line" href="uart_8c.html#ae6fa1b5eca1c33c10c65e46a88eaf934">   22</a></span><span class="keyword">volatile</span> <span class="keyword">static</span> <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> <a class="code hl_variable" href="uart_8c.html#ae6fa1b5eca1c33c10c65e46a88eaf934">mdtp_receive_status</a> = 0;</div>
<div class="line"><a id="l00026" name="l00026"></a><span class="lineno"><a class="line" href="uart_8c.html#a6e6e7fd37513522129125894f141f19f">   26</a></span><span class="keyword">volatile</span> <span class="keyword">static</span> <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> <a class="code hl_variable" href="uart_8c.html#a6e6e7fd37513522129125894f141f19f">mdtp_receive_number_counter</a> = 0;</div>
<div class="line"><a id="l00030" name="l00030"></a><span class="lineno"><a class="line" href="uart_8c.html#a8967fc1147a3c08266cd57e7210f4fae">   30</a></span><span class="keyword">static</span> <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> <a class="code hl_variable" href="uart_8c.html#a8967fc1147a3c08266cd57e7210f4fae">mdtp_receive_data_buffer</a>[10] = {0};</div>
<div class="line"><a id="l00031" name="l00031"></a><span class="lineno">   31</span> </div>
<div class="line"><a id="l00037" name="l00037"></a><span class="lineno"><a class="line" href="uart_8c.html#a8b1fe807c1672229711abeb195185046">   37</a></span><span class="keywordtype">void</span> <a class="code hl_function" href="uart_8c.html#a8b1fe807c1672229711abeb195185046">mdtp_receive_handler</a>(<span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> data) {</div>
<div class="line"><a id="l00038" name="l00038"></a><span class="lineno">   38</span>    <span class="comment">/* data receiving finite state machine */</span></div>
<div class="line"><a id="l00039" name="l00039"></a><span class="lineno">   39</span>    <span class="keywordflow">switch</span> (<a class="code hl_variable" href="uart_8c.html#ae6fa1b5eca1c33c10c65e46a88eaf934">mdtp_receive_status</a>) {</div>
<div class="line"><a id="l00040" name="l00040"></a><span class="lineno">   40</span>        <span class="keywordflow">case</span> 0:</div>
<div class="line"><a id="l00041" name="l00041"></a><span class="lineno">   41</span>            <span class="comment">/* judge whether the packet header is received */</span></div>
<div class="line"><a id="l00042" name="l00042"></a><span class="lineno">   42</span>            <span class="keywordflow">if</span> (data == 0xff) {</div>
<div class="line"><a id="l00043" name="l00043"></a><span class="lineno">   43</span>                <span class="comment">/* enter the receive state */</span></div>
<div class="line"><a id="l00044" name="l00044"></a><span class="lineno">   44</span>                <a class="code hl_variable" href="uart_8c.html#ae6fa1b5eca1c33c10c65e46a88eaf934">mdtp_receive_status</a> = 1;</div>
<div class="line"><a id="l00045" name="l00045"></a><span class="lineno">   45</span> </div>
<div class="line"><a id="l00046" name="l00046"></a><span class="lineno">   46</span>                <span class="comment">/* clear receive array counter and buffer */</span></div>
<div class="line"><a id="l00047" name="l00047"></a><span class="lineno">   47</span>                <a class="code hl_variable" href="uart_8c.html#a6e6e7fd37513522129125894f141f19f">mdtp_receive_number_counter</a> = 0;</div>
<div class="line"><a id="l00048" name="l00048"></a><span class="lineno">   48</span>                <a class="code hl_function" href="system_8c.html#a7e7cece1b30ef67968b244698f999b0e">user_memset</a>(<a class="code hl_variable" href="uart_8c.html#a8967fc1147a3c08266cd57e7210f4fae">mdtp_receive_data_buffer</a>, 0x00, <span class="keyword">sizeof</span>(<a class="code hl_variable" href="uart_8c.html#a8967fc1147a3c08266cd57e7210f4fae">mdtp_receive_data_buffer</a>));</div>
<div class="line"><a id="l00049" name="l00049"></a><span class="lineno">   49</span>            }</div>
<div class="line"><a id="l00050" name="l00050"></a><span class="lineno">   50</span>            <span class="keywordflow">break</span>;</div>
<div class="line"><a id="l00051" name="l00051"></a><span class="lineno">   51</span> </div>
<div class="line"><a id="l00052" name="l00052"></a><span class="lineno">   52</span>        <span class="keywordflow">case</span> 1:</div>
<div class="line"><a id="l00053" name="l00053"></a><span class="lineno">   53</span>            <span class="comment">/* judge whether the end of the packet is mistakenly recognized as the header */</span></div>
<div class="line"><a id="l00054" name="l00054"></a><span class="lineno">   54</span>            <span class="keywordflow">if</span> (data == 0xff &amp;&amp; <a class="code hl_variable" href="uart_8c.html#a6e6e7fd37513522129125894f141f19f">mdtp_receive_number_counter</a> != 0) {</div>
<div class="line"><a id="l00055" name="l00055"></a><span class="lineno">   55</span>                <span class="comment">/* an unexpected data had been received */</span></div>
<div class="line"><a id="l00056" name="l00056"></a><span class="lineno">   56</span>                <span class="comment">/* reset to receive start of package state */</span></div>
<div class="line"><a id="l00057" name="l00057"></a><span class="lineno">   57</span>                <a class="code hl_variable" href="uart_8c.html#ae6fa1b5eca1c33c10c65e46a88eaf934">mdtp_receive_status</a> = 0;</div>
<div class="line"><a id="l00058" name="l00058"></a><span class="lineno">   58</span> </div>
<div class="line"><a id="l00059" name="l00059"></a><span class="lineno">   59</span>                <span class="comment">/* clear receive array counter and buffer */</span></div>
<div class="line"><a id="l00060" name="l00060"></a><span class="lineno">   60</span>                <a class="code hl_variable" href="uart_8c.html#a6e6e7fd37513522129125894f141f19f">mdtp_receive_number_counter</a> = 0;</div>
<div class="line"><a id="l00061" name="l00061"></a><span class="lineno">   61</span>                <a class="code hl_function" href="system_8c.html#a7e7cece1b30ef67968b244698f999b0e">user_memset</a>(<a class="code hl_variable" href="uart_8c.html#a8967fc1147a3c08266cd57e7210f4fae">mdtp_receive_data_buffer</a>, 0x00, <span class="keyword">sizeof</span>(<a class="code hl_variable" href="uart_8c.html#a8967fc1147a3c08266cd57e7210f4fae">mdtp_receive_data_buffer</a>));</div>
<div class="line"><a id="l00062" name="l00062"></a><span class="lineno">   62</span>            } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (data != 0xff) {</div>
<div class="line"><a id="l00063" name="l00063"></a><span class="lineno">   63</span>                <span class="comment">/* judge whether the reception is completed or the error data is received */</span></div>
<div class="line"><a id="l00064" name="l00064"></a><span class="lineno">   64</span>                <span class="keywordflow">if</span> (<a class="code hl_variable" href="uart_8c.html#a6e6e7fd37513522129125894f141f19f">mdtp_receive_number_counter</a> != 10) {</div>
<div class="line"><a id="l00065" name="l00065"></a><span class="lineno">   65</span>                    <span class="comment">/* receive the data into the array in turn */</span></div>
<div class="line"><a id="l00066" name="l00066"></a><span class="lineno">   66</span>                    <a class="code hl_variable" href="uart_8c.html#a8967fc1147a3c08266cd57e7210f4fae">mdtp_receive_data_buffer</a>[<a class="code hl_variable" href="uart_8c.html#a6e6e7fd37513522129125894f141f19f">mdtp_receive_number_counter</a>] = data;</div>
<div class="line"><a id="l00067" name="l00067"></a><span class="lineno">   67</span>                    <a class="code hl_variable" href="uart_8c.html#a6e6e7fd37513522129125894f141f19f">mdtp_receive_number_counter</a> = <a class="code hl_variable" href="uart_8c.html#a6e6e7fd37513522129125894f141f19f">mdtp_receive_number_counter</a> + 1;</div>
<div class="line"><a id="l00068" name="l00068"></a><span class="lineno">   68</span>                    <span class="keywordflow">if</span> (<a class="code hl_variable" href="uart_8c.html#a6e6e7fd37513522129125894f141f19f">mdtp_receive_number_counter</a> == 10)</div>
<div class="line"><a id="l00069" name="l00069"></a><span class="lineno">   69</span>                        <a class="code hl_variable" href="uart_8c.html#ae6fa1b5eca1c33c10c65e46a88eaf934">mdtp_receive_status</a> = 2;</div>
<div class="line"><a id="l00070" name="l00070"></a><span class="lineno">   70</span>                }</div>
<div class="line"><a id="l00071" name="l00071"></a><span class="lineno">   71</span>            }</div>
<div class="line"><a id="l00072" name="l00072"></a><span class="lineno">   72</span>            <span class="keywordflow">break</span>;</div>
<div class="line"><a id="l00073" name="l00073"></a><span class="lineno">   73</span> </div>
<div class="line"><a id="l00074" name="l00074"></a><span class="lineno">   74</span>        <span class="keywordflow">case</span> 2:</div>
<div class="line"><a id="l00075" name="l00075"></a><span class="lineno">   75</span>            <span class="keywordflow">if</span> (data == 0xff) {</div>
<div class="line"><a id="l00076" name="l00076"></a><span class="lineno">   76</span>                <a class="code hl_variable" href="uart_8c.html#ae6fa1b5eca1c33c10c65e46a88eaf934">mdtp_receive_status</a> = 0;</div>
<div class="line"><a id="l00077" name="l00077"></a><span class="lineno">   77</span> </div>
<div class="line"><a id="l00078" name="l00078"></a><span class="lineno">   78</span>                <span class="comment">/* verify whether the pid byte is correct*/</span></div>
<div class="line"><a id="l00079" name="l00079"></a><span class="lineno">   79</span>                <span class="keywordflow">if</span> ((<a class="code hl_variable" href="uart_8c.html#a8967fc1147a3c08266cd57e7210f4fae">mdtp_receive_data_buffer</a>[0] &gt;&gt; 4) == (~<a class="code hl_variable" href="uart_8c.html#a8967fc1147a3c08266cd57e7210f4fae">mdtp_receive_data_buffer</a>[0] &amp; 0x0f)) {</div>
<div class="line"><a id="l00080" name="l00080"></a><span class="lineno">   80</span>                    <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> tmp_rcv_buffer[8], counter = 0;</div>
<div class="line"><a id="l00081" name="l00081"></a><span class="lineno">   81</span>                    <span class="comment">/* judge whether the package content is all 0xff */</span></div>
<div class="line"><a id="l00082" name="l00082"></a><span class="lineno">   82</span>                    <span class="keywordflow">if</span> (<a class="code hl_variable" href="uart_8c.html#a8967fc1147a3c08266cd57e7210f4fae">mdtp_receive_data_buffer</a>[1] == 0xa5 &amp;&amp; <a class="code hl_variable" href="uart_8c.html#a8967fc1147a3c08266cd57e7210f4fae">mdtp_receive_data_buffer</a>[9] == 0xa5)</div>
<div class="line"><a id="l00083" name="l00083"></a><span class="lineno">   83</span>                        <a class="code hl_function" href="system_8c.html#a7e7cece1b30ef67968b244698f999b0e">user_memset</a>(tmp_rcv_buffer, 0xff, <span class="keyword">sizeof</span>(tmp_rcv_buffer));</div>
<div class="line"><a id="l00084" name="l00084"></a><span class="lineno">   84</span>                    <span class="keywordflow">else</span> {</div>
<div class="line"><a id="l00085" name="l00085"></a><span class="lineno">   85</span>                        <span class="comment">/* traverse the data byte to be adjusted */</span></div>
<div class="line"><a id="l00086" name="l00086"></a><span class="lineno">   86</span>                        <span class="keywordflow">for</span> (; counter &lt; 8; ++counter)</div>
<div class="line"><a id="l00087" name="l00087"></a><span class="lineno">   87</span>                            <span class="keywordflow">if</span> (((<a class="code hl_variable" href="uart_8c.html#a8967fc1147a3c08266cd57e7210f4fae">mdtp_receive_data_buffer</a>[9] &gt;&gt; counter) &amp; 0x01) == 0x01)</div>
<div class="line"><a id="l00088" name="l00088"></a><span class="lineno">   88</span>                                tmp_rcv_buffer[counter] = 0xff;</div>
<div class="line"><a id="l00089" name="l00089"></a><span class="lineno">   89</span>                            <span class="keywordflow">else</span></div>
<div class="line"><a id="l00090" name="l00090"></a><span class="lineno">   90</span>                                tmp_rcv_buffer[counter] = <a class="code hl_variable" href="uart_8c.html#a8967fc1147a3c08266cd57e7210f4fae">mdtp_receive_data_buffer</a>[counter + 1];</div>
<div class="line"><a id="l00091" name="l00091"></a><span class="lineno">   91</span>                    }</div>
<div class="line"><a id="l00092" name="l00092"></a><span class="lineno">   92</span>                    <span class="comment">/* call user callback function to complete the next step */</span></div>
<div class="line"><a id="l00093" name="l00093"></a><span class="lineno">   93</span>                    <a class="code hl_function" href="uart_8h.html#a6d278b36110f5f0e56b59e058b867b65">mdtp_callback_handler</a>(<a class="code hl_variable" href="uart_8c.html#a8967fc1147a3c08266cd57e7210f4fae">mdtp_receive_data_buffer</a>[0] &gt;&gt; 4, tmp_rcv_buffer);</div>
<div class="line"><a id="l00094" name="l00094"></a><span class="lineno">   94</span>                }</div>
<div class="line"><a id="l00095" name="l00095"></a><span class="lineno">   95</span>            } <span class="keywordflow">else</span> {</div>
<div class="line"><a id="l00096" name="l00096"></a><span class="lineno">   96</span>                <span class="comment">/* an unexpected data had been received */</span></div>
<div class="line"><a id="l00097" name="l00097"></a><span class="lineno">   97</span>                <span class="comment">/* reset to receive start of package state */</span></div>
<div class="line"><a id="l00098" name="l00098"></a><span class="lineno">   98</span>                <a class="code hl_variable" href="uart_8c.html#ae6fa1b5eca1c33c10c65e46a88eaf934">mdtp_receive_status</a> = 0;</div>
<div class="line"><a id="l00099" name="l00099"></a><span class="lineno">   99</span> </div>
<div class="line"><a id="l00100" name="l00100"></a><span class="lineno">  100</span>                <span class="comment">/* clear receive array counter and buffer */</span></div>
<div class="line"><a id="l00101" name="l00101"></a><span class="lineno">  101</span>                <a class="code hl_variable" href="uart_8c.html#a6e6e7fd37513522129125894f141f19f">mdtp_receive_number_counter</a> = 0;</div>
<div class="line"><a id="l00102" name="l00102"></a><span class="lineno">  102</span>                <a class="code hl_function" href="system_8c.html#a7e7cece1b30ef67968b244698f999b0e">user_memset</a>(<a class="code hl_variable" href="uart_8c.html#a8967fc1147a3c08266cd57e7210f4fae">mdtp_receive_data_buffer</a>, 0x00, <span class="keyword">sizeof</span>(<a class="code hl_variable" href="uart_8c.html#a8967fc1147a3c08266cd57e7210f4fae">mdtp_receive_data_buffer</a>));</div>
<div class="line"><a id="l00103" name="l00103"></a><span class="lineno">  103</span>            }</div>
<div class="line"><a id="l00104" name="l00104"></a><span class="lineno">  104</span>            <span class="keywordflow">break</span>;</div>
<div class="line"><a id="l00105" name="l00105"></a><span class="lineno">  105</span>    }</div>
<div class="line"><a id="l00106" name="l00106"></a><span class="lineno">  106</span>}</div>
<div class="line"><a id="l00107" name="l00107"></a><span class="lineno">  107</span> </div>
<div class="line"><a id="l00114" name="l00114"></a><span class="lineno"><a class="line" href="uart_8c.html#ab01834c3618e9e1078f1b7e9512337c6">  114</a></span><span class="keywordtype">void</span> <a class="code hl_function" href="uart_8c.html#ab01834c3618e9e1078f1b7e9512337c6">mdtp_data_transmit</a>(<span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> pid, <span class="keyword">const</span> <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> *buffer) {</div>
<div class="line"><a id="l00115" name="l00115"></a><span class="lineno">  115</span>    <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> temp_buf[12] = {0xff, 0x00, 0x00, 0x00, 0x00, 0x00,</div>
<div class="line"><a id="l00116" name="l00116"></a><span class="lineno">  116</span>                                  0x00, 0x00, 0x00, 0x00, 0x00, 0xff};</div>
<div class="line"><a id="l00117" name="l00117"></a><span class="lineno">  117</span>    <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> mdtp_pack_counter;</div>
<div class="line"><a id="l00118" name="l00118"></a><span class="lineno">  118</span> </div>
<div class="line"><a id="l00119" name="l00119"></a><span class="lineno">  119</span>    <span class="comment">/* traverse the array to determine whether there are bytes to be adjusted */</span></div>
<div class="line"><a id="l00120" name="l00120"></a><span class="lineno">  120</span>    <span class="keywordflow">for</span> (mdtp_pack_counter = 0; mdtp_pack_counter &lt; 8; mdtp_pack_counter++) {</div>
<div class="line"><a id="l00121" name="l00121"></a><span class="lineno">  121</span>        <span class="keywordflow">if</span> (buffer[mdtp_pack_counter] == 0xff) {</div>
<div class="line"><a id="l00122" name="l00122"></a><span class="lineno">  122</span>            temp_buf[2 + mdtp_pack_counter] = 0x00;</div>
<div class="line"><a id="l00123" name="l00123"></a><span class="lineno">  123</span>            temp_buf[10] = (temp_buf[10] | (1 &lt;&lt; mdtp_pack_counter));</div>
<div class="line"><a id="l00124" name="l00124"></a><span class="lineno">  124</span>        } <span class="keywordflow">else</span></div>
<div class="line"><a id="l00125" name="l00125"></a><span class="lineno">  125</span>            temp_buf[2 + mdtp_pack_counter] = buffer[mdtp_pack_counter];</div>
<div class="line"><a id="l00126" name="l00126"></a><span class="lineno">  126</span>    }</div>
<div class="line"><a id="l00127" name="l00127"></a><span class="lineno">  127</span> </div>
<div class="line"><a id="l00128" name="l00128"></a><span class="lineno">  128</span>    <span class="comment">/* judge whether the package is all 0xff */</span></div>
<div class="line"><a id="l00129" name="l00129"></a><span class="lineno">  129</span>    <span class="keywordflow">if</span> (temp_buf[10] == 0xff)</div>
<div class="line"><a id="l00130" name="l00130"></a><span class="lineno">  130</span>        temp_buf[10] = temp_buf[2] = 0xa5;</div>
<div class="line"><a id="l00131" name="l00131"></a><span class="lineno">  131</span> </div>
<div class="line"><a id="l00132" name="l00132"></a><span class="lineno">  132</span>    <span class="comment">/* load self checking packet id byte */</span></div>
<div class="line"><a id="l00133" name="l00133"></a><span class="lineno">  133</span>    temp_buf[1] = pid &lt;&lt; 4 | ((~pid) &amp; 0x0f);</div>
<div class="line"><a id="l00134" name="l00134"></a><span class="lineno">  134</span> </div>
<div class="line"><a id="l00135" name="l00135"></a><span class="lineno">  135</span>    <span class="comment">/* traverse the buffer array and send all bytes through UART0 */</span></div>
<div class="line"><a id="l00136" name="l00136"></a><span class="lineno">  136</span>    <span class="keywordflow">for</span> (mdtp_pack_counter = 0; mdtp_pack_counter &lt; 12;</div>
<div class="line"><a id="l00137" name="l00137"></a><span class="lineno">  137</span>         mdtp_pack_counter++) { <a class="code hl_define" href="uart_8h.html#ad0829c8bd2841fd6525781b3dbf496b7">uart_sendbyte</a>(temp_buf[mdtp_pack_counter]);</div>
<div class="line"><a id="l00138" name="l00138"></a><span class="lineno">  138</span>    }</div>
<div class="line"><a id="l00139" name="l00139"></a><span class="lineno">  139</span>}</div>
<div class="line"><a id="l00140" name="l00140"></a><span class="lineno">  140</span> </div>
<div class="line"><a id="l00145" name="l00145"></a><span class="lineno"><a class="line" href="uart_8c.html#afb2565a333438fc66b5725bf1e41ca0f">  145</a></span><span class="keywordtype">void</span> <a class="code hl_function" href="uart_8c.html#afb2565a333438fc66b5725bf1e41ca0f">uart_config</a>(<span class="keywordtype">void</span>) {</div>
<div class="line"><a id="l00146" name="l00146"></a><span class="lineno">  146</span>    <span class="comment">/* UART interrupt configuration */</span></div>
<div class="line"><a id="l00147" name="l00147"></a><span class="lineno">  147</span>    nvic_irq_enable(USART0_IRQn, <a class="code hl_define" href="config_8h.html#a7bb8116c0084a1decc494f532e229e1e">UART_PRIORITY</a>, 0);</div>
<div class="line"><a id="l00148" name="l00148"></a><span class="lineno">  148</span> </div>
<div class="line"><a id="l00149" name="l00149"></a><span class="lineno">  149</span>    <span class="comment">/* enable GPIO clock and UART clock*/</span></div>
<div class="line"><a id="l00150" name="l00150"></a><span class="lineno">  150</span>    rcu_periph_clock_enable(RCU_GPIOA);</div>
<div class="line"><a id="l00151" name="l00151"></a><span class="lineno">  151</span>    rcu_periph_clock_enable(RCU_USART0);</div>
<div class="line"><a id="l00152" name="l00152"></a><span class="lineno">  152</span> </div>
<div class="line"><a id="l00153" name="l00153"></a><span class="lineno">  153</span>    <span class="comment">/* connect port to UARTx */</span></div>
<div class="line"><a id="l00154" name="l00154"></a><span class="lineno">  154</span>    gpio_af_set(GPIOA, GPIO_AF_1, GPIO_PIN_9);</div>
<div class="line"><a id="l00155" name="l00155"></a><span class="lineno">  155</span>    gpio_af_set(GPIOA, GPIO_AF_1, GPIO_PIN_10);</div>
<div class="line"><a id="l00156" name="l00156"></a><span class="lineno">  156</span> </div>
<div class="line"><a id="l00157" name="l00157"></a><span class="lineno">  157</span>    <span class="comment">/* configure UART Tx as alternate function push-pull */</span></div>
<div class="line"><a id="l00158" name="l00158"></a><span class="lineno">  158</span>    gpio_mode_set(GPIOA, GPIO_MODE_AF, GPIO_PUPD_PULLUP, GPIO_PIN_9);</div>
<div class="line"><a id="l00159" name="l00159"></a><span class="lineno">  159</span>    gpio_output_options_set(GPIOA, GPIO_OTYPE_PP, GPIO_OSPEED_10MHZ, GPIO_PIN_9);</div>
<div class="line"><a id="l00160" name="l00160"></a><span class="lineno">  160</span> </div>
<div class="line"><a id="l00161" name="l00161"></a><span class="lineno">  161</span>    <span class="comment">/* configure UART Rx as alternate function push-pull */</span></div>
<div class="line"><a id="l00162" name="l00162"></a><span class="lineno">  162</span>    gpio_mode_set(GPIOA, GPIO_MODE_AF, GPIO_PUPD_PULLUP, GPIO_PIN_10);</div>
<div class="line"><a id="l00163" name="l00163"></a><span class="lineno">  163</span>    gpio_output_options_set(GPIOA, GPIO_OTYPE_PP, GPIO_OSPEED_10MHZ, GPIO_PIN_10);</div>
<div class="line"><a id="l00164" name="l00164"></a><span class="lineno">  164</span> </div>
<div class="line"><a id="l00165" name="l00165"></a><span class="lineno">  165</span>    <span class="comment">/* UART configure */</span></div>
<div class="line"><a id="l00166" name="l00166"></a><span class="lineno">  166</span>    usart_deinit(USART0);</div>
<div class="line"><a id="l00167" name="l00167"></a><span class="lineno">  167</span>    usart_baudrate_set(USART0, <a class="code hl_define" href="config_8h.html#a2c7ed0283bd6f2f9d791860d6254ef4f">UART_BAUDRATE</a>);</div>
<div class="line"><a id="l00168" name="l00168"></a><span class="lineno">  168</span>    usart_transmit_config(USART0, USART_TRANSMIT_ENABLE);</div>
<div class="line"><a id="l00169" name="l00169"></a><span class="lineno">  169</span>    usart_receive_config(USART0, USART_RECEIVE_ENABLE);</div>
<div class="line"><a id="l00170" name="l00170"></a><span class="lineno">  170</span>    usart_enable(USART0);</div>
<div class="line"><a id="l00171" name="l00171"></a><span class="lineno">  171</span> </div>
<div class="line"><a id="l00172" name="l00172"></a><span class="lineno">  172</span>    <span class="comment">/* enable UART RBNE interrupt */</span></div>
<div class="line"><a id="l00173" name="l00173"></a><span class="lineno">  173</span>    usart_interrupt_enable(USART0, USART_INT_RBNE);</div>
<div class="line"><a id="l00174" name="l00174"></a><span class="lineno">  174</span>}</div>
<div class="ttc" id="aconfig_8h_html"><div class="ttname"><a href="config_8h.html">config.h</a></div><div class="ttdoc">used to place important parameter configurations for users</div></div>
<div class="ttc" id="aconfig_8h_html_a2c7ed0283bd6f2f9d791860d6254ef4f"><div class="ttname"><a href="config_8h.html#a2c7ed0283bd6f2f9d791860d6254ef4f">UART_BAUDRATE</a></div><div class="ttdeci">#define UART_BAUDRATE</div><div class="ttdoc">set UART baud rate to 115200</div><div class="ttdef"><b>Definition:</b> <a href="config_8h_source.html#l00022">config.h:22</a></div></div>
<div class="ttc" id="aconfig_8h_html_a7bb8116c0084a1decc494f532e229e1e"><div class="ttname"><a href="config_8h.html#a7bb8116c0084a1decc494f532e229e1e">UART_PRIORITY</a></div><div class="ttdeci">#define UART_PRIORITY</div><div class="ttdoc">UART preemption priority set to 1.</div><div class="ttdef"><b>Definition:</b> <a href="config_8h_source.html#l00035">config.h:35</a></div></div>
<div class="ttc" id="asystem_8c_html_a7e7cece1b30ef67968b244698f999b0e"><div class="ttname"><a href="system_8c.html#a7e7cece1b30ef67968b244698f999b0e">user_memset</a></div><div class="ttdeci">void user_memset(void *buf, unsigned char data, unsigned char num)</div><div class="ttdoc">format buffer array to fixed value, replace memset function</div><div class="ttdef"><b>Definition:</b> <a href="system_8c_source.html#l00054">system.c:54</a></div></div>
<div class="ttc" id="asystem_8h_html"><div class="ttname"><a href="system_8h.html">system.h</a></div><div class="ttdoc">system basic function header file</div></div>
<div class="ttc" id="auart_8c_html_a6e6e7fd37513522129125894f141f19f"><div class="ttname"><a href="uart_8c.html#a6e6e7fd37513522129125894f141f19f">mdtp_receive_number_counter</a></div><div class="ttdeci">static volatile unsigned char mdtp_receive_number_counter</div><div class="ttdoc">medium capacity transport protocol receive character counter</div><div class="ttdef"><b>Definition:</b> <a href="uart_8c_source.html#l00026">uart.c:26</a></div></div>
<div class="ttc" id="auart_8c_html_a8967fc1147a3c08266cd57e7210f4fae"><div class="ttname"><a href="uart_8c.html#a8967fc1147a3c08266cd57e7210f4fae">mdtp_receive_data_buffer</a></div><div class="ttdeci">static unsigned char mdtp_receive_data_buffer[10]</div><div class="ttdoc">medium capacity transport protocol receive buffer array</div><div class="ttdef"><b>Definition:</b> <a href="uart_8c_source.html#l00030">uart.c:30</a></div></div>
<div class="ttc" id="auart_8c_html_a8b1fe807c1672229711abeb195185046"><div class="ttname"><a href="uart_8c.html#a8b1fe807c1672229711abeb195185046">mdtp_receive_handler</a></div><div class="ttdeci">void mdtp_receive_handler(unsigned char data)</div><div class="ttdoc">medium capacity data transmission protocol unpacking handler</div><div class="ttdef"><b>Definition:</b> <a href="uart_8c_source.html#l00037">uart.c:37</a></div></div>
<div class="ttc" id="auart_8c_html_ab01834c3618e9e1078f1b7e9512337c6"><div class="ttname"><a href="uart_8c.html#ab01834c3618e9e1078f1b7e9512337c6">mdtp_data_transmit</a></div><div class="ttdeci">void mdtp_data_transmit(unsigned char pid, const unsigned char *buffer)</div><div class="ttdoc">medium capacity data transmission protocol packing function</div><div class="ttdef"><b>Definition:</b> <a href="uart_8c_source.html#l00114">uart.c:114</a></div></div>
<div class="ttc" id="auart_8c_html_ae6fa1b5eca1c33c10c65e46a88eaf934"><div class="ttname"><a href="uart_8c.html#ae6fa1b5eca1c33c10c65e46a88eaf934">mdtp_receive_status</a></div><div class="ttdeci">static volatile unsigned char mdtp_receive_status</div><div class="ttdoc">medium capacity transport protocol receive state variable 0 idle state and waiting for start of packa...</div><div class="ttdef"><b>Definition:</b> <a href="uart_8c_source.html#l00022">uart.c:22</a></div></div>
<div class="ttc" id="auart_8c_html_afb2565a333438fc66b5725bf1e41ca0f"><div class="ttname"><a href="uart_8c.html#afb2565a333438fc66b5725bf1e41ca0f">uart_config</a></div><div class="ttdeci">void uart_config(void)</div><div class="ttdoc">configure uart0 periph and its gpios</div><div class="ttdef"><b>Definition:</b> <a href="uart_8c_source.html#l00145">uart.c:145</a></div></div>
<div class="ttc" id="auart_8h_html"><div class="ttname"><a href="uart_8h.html">uart.h</a></div><div class="ttdoc">this is the header file of uart.c.</div></div>
<div class="ttc" id="auart_8h_html_a6d278b36110f5f0e56b59e058b867b65"><div class="ttname"><a href="uart_8h.html#a6d278b36110f5f0e56b59e058b867b65">mdtp_callback_handler</a></div><div class="ttdeci">void mdtp_callback_handler(unsigned char pid, const unsigned char *data)</div><div class="ttdoc">user callback function for unpacking completion of medium capacity transport protocol</div><div class="ttdef"><b>Definition:</b> <a href="main_8c_source.html#l00029">main.c:29</a></div></div>
<div class="ttc" id="auart_8h_html_ad0829c8bd2841fd6525781b3dbf496b7"><div class="ttname"><a href="uart_8h.html#ad0829c8bd2841fd6525781b3dbf496b7">uart_sendbyte</a></div><div class="ttdeci">#define uart_sendbyte(x)</div><div class="ttdoc">UART send single byte macro.</div><div class="ttdef"><b>Definition:</b> <a href="uart_8h_source.html#l00017">uart.h:17</a></div></div>
</div><!-- fragment --></div><!-- contents -->
<!-- start footer part -->
<hr class="footer"/><address class="footer"><small>
Generated by&#160;<a href="https://www.doxygen.org/index.html"><img class="footer" src="doxygen.svg" width="104" height="31" alt="doxygen"/></a> 1.9.2
</small></address>
</body>
</html>
